import { Injectable } from '@angular/core';

import { Observable, of } from 'rxjs';
import { map, filter } from 'rxjs/operators';

import { Importedfile, ImageItemDetail, DesignEntity, ScreenItemDescriptionEntity, ItemControlEntity } from './imported-file';
import { Importedfiles, ImageItemDetails } from './mock-imported-files';
import { MessageService } from '../message.service';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Injectable({
  providedIn: 'root',
})
export class ImportedFileService {
  constructor(private http:HttpClient,private messageService: MessageService) {}

  // 設計書一覧取得
  getImportedfiles(): Observable<DesignEntity[]> {
    // TODO: send the message _after_ fetching the heroes
    this.messageService.add('importedFileService: fetched importedFiles');
    return this.http.get<DesignEntity[]>("getDesignList");
  }

  // 設計書一覧取得
  getImportedfileList(screenId : string, designTypeId : string): Observable<DesignEntity[]> {

    const data = {
      'screenId': screenId,
      'designTypeId':designTypeId
   };
    return this.http.get<DesignEntity[]>("getDesignList", {params: data});
  }

  // 画面項目記述書アイテム一覧取得
  getImageitemDetails(screenId : string, designTypeId : string): Observable<ScreenItemDescriptionEntity[]> {
    // TODO: send the message _after_ fetching the heroes
    this.messageService.add('importedFileService: fetched importedFiles');

    const data = {
      'screenId': screenId,
      'designTypeId':designTypeId
   };

   return this.http.get<ScreenItemDescriptionEntity[]>("getScreenItemDescriptionList", {params: data});
  }

  integrityCheck(imageItemDetaillist: ScreenItemDescriptionEntity[]):Observable<ScreenItemDescriptionEntity[]> {
    
    const httpOptions = {headers: new HttpHeaders({'Content-Type': 'application/json'})};
    const imageItemDetails = JSON.stringify(imageItemDetaillist);
    return this.http.post<ScreenItemDescriptionEntity[]>("integrityCheck", imageItemDetails, httpOptions);
  }
  
  integrityCheck2(imageItemDetaillist: ScreenItemDescriptionEntity[]):Observable<ScreenItemDescriptionEntity[]> {
    
    const httpOptions = {headers: new HttpHeaders({'Content-Type': 'application/json'})};
    const imageItemDetails = JSON.stringify(imageItemDetaillist);
    return this.http.post<ScreenItemDescriptionEntity[]>("integrityCheck2", imageItemDetails, httpOptions);
  }

  integrityCheck3(imageItemDetaillist: ScreenItemDescriptionEntity[]):Observable<ItemControlEntity[]> {
    
    const httpOptions = {headers: new HttpHeaders({'Content-Type': 'application/json'})};
    const imageItemDetails = JSON.stringify(imageItemDetaillist);
    return this.http.post<ItemControlEntity[]>("integrityCheck3", imageItemDetails, httpOptions);
  }

  getScreenIdList(): Observable<Array<string>> {

    return this.http.get<Array<string>>("getScreenIdList1");
  }
}

